home *** CD-ROM | disk | FTP | other *** search
- /*
- DispCtrl.h
-
- Display Controller routines for Graphic Elements
-
- Copyright 1994 by Al Evans. All rights reserved.
-
- 3/7/94
-
- Updated 5/25/95 for Graphic Elements version 3.0
-
- */
-
- #ifndef DISPCTRL
- #define DISPCTRL
-
- #include "Defs.h"
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- //Creation of new GEWorld
-
- /*
- Returns pointer to a new GEWorld. This world covers the area of worldPort
- specified by worldRect (in port coordinates), if scale is scaleOneToOne.
-
- Scale determines the interpretation of the position and size of worldRect
- within worldPort. Briefly, if a GEWorld has a certain position and size in
- a GrafPort at scaleOneToOne, that GEWorld will have the same *relative* position
- and size, if the horizontal and vertical dimensions of the GrafPort are halved,
- at a scale of 0x00008000 (0.5 in fixed-point notation).
-
- If it is not nil, worldColors must be a handle to a color table appropriate
- for an 8-bit depth.
-
- */
-
- GEWorldPtr NewGEWorld(GrafPtr worldPort, Rect *worldRect, Fixed scale, CTabHandle worldColors);
-
-
- //Destruction of a GEWorld
-
- /*
- Disposes of a world and everything in it.
- */
-
- void DisposeGEWorld(GEWorldPtr world);
-
-
- //Management of a GEWorld
-
- /*
- Set default loader function for world. If no loader is specified when a new
- Graphic Element is created, this function is used.
-
- In a newly-created world, this loader function is one which creates an offscreen
- GWorld and loads one or more PICTS from an open resource fork into it.
- */
-
- void SetDefaultLoadFunc(GEWorldPtr world, GraphicLoadFunc loader);
-
- /*
- Set frame post-processing function and data for world. If this function is
- present, it will be called after every frame update.
- */
-
- void SetPostProcFunc(GEWorldPtr world, FramePostProcFunc postProcFunc, Ptr postProcData);
-
- /*
-
- Activate or deactivate an individual world
- */
-
- void ActivateWorld(GEWorldPtr world, Boolean turnItOn);
-
- /*
- Get and set projection rate
- These are NOT very useful, but MAY improve performance in some situations on
- slower machines.
- */
-
- void SetProjectionRate(GEWorldPtr world, short newMSPerFrame);
-
- short GetProjectionRate(GEWorldPtr world);
-
- /*
- Control GEWorld's timer
- */
-
- void StartGETimer(GEWorldPtr world);
-
- void StopGETimer(GEWorldPtr world);
-
-
- //Returns current time in world
- unsigned long CurrentGETime(GEWorldPtr world);
-
- /* Set the number of timer milliseconds that pass per "real"
- millisecond. newRate is treated as a fixed-point number,
- with a two-byte positive integer and a two byte fraction,
- such that a value of 0x00010000 will give a 1-to-1
- correspondence between Graphic Elements "milliseconds"
- and real milliseconds.
- */
-
- void SetGETimerRate(GEWorldPtr world, unsigned long newRate);
-
- //Returns current "rate" of timer in world
- unsigned long GetGETimerRate(GEWorldPtr world);
-
- /*
- Manipulate world coordinate system;
- */
-
- /*
- GetGEWorldFocus and SetGEWorldFocus should be used to "bracket" calls to
- FocusOnGEWorld, in order to save and restore the previous focus.
- */
-
- void GetGEWorldFocus(GEWorldPtr world, Point *currFocus);
- void SetGEWorldFocus(GEWorldPtr world, Point newFocus);
-
- /*
- Sets focus, i.e. coordinate system, to that of world
- */
-
- void FocusOnGEWorld(GEWorldPtr world);
-
- /*
- Keeps display controller from drawing into a portion of world has been covered by other
- graphics which should be protected. The Rect is in the coordinates of the GEWorld's
- enclosing GrafPort.
- */
-
- void CoverRect(GEWorldPtr world, Rect *coveredRect);
-
- /*
- Like CoverRect(), but protects any region
- */
-
- void CoverRegion(GEWorldPtr world, RgnHandle coveredRgn);
-
- /*
- Uncovers a rect -- opposite of CoverRect()
- */
-
- void UncoverRect(GEWorldPtr world, Rect *rectToUncover);
-
- /*
- Like UncoverRect, but uncovers any region
- */
-
- void UncoverRegion(GEWorldPtr world, RgnHandle rgnToUncover);
-
- /*
- Undoes the effects of ALL calls to CoverRect() or CoverRegion()
- */
-
- void UncoverWorld(GEWorldPtr world);
-
- /*
- Move an entire GEWorld relative to its window
- */
-
- void MoveGEWorld(GEWorldPtr world, short dh, short dv);
- void MoveGEWorldTo(GEWorldPtr world, short h, short v);
-
- /*
- Scale a distance to the current world's worldScale.
- This is necessary ONLY in creating new Graphic Elements,
- for determining size and position within a world.
-
- Returns value * world->worldScale / 65536. If result is 0, returns
- 1 if value was positive, -1 if value was negative.
- */
-
- short ScaleToWorld(GEWorldPtr world, short value);
-
- /*
- Generate a frame showing the world in its current state and display it on the screen.
- Should be called frequently from application program, for example once each time
- through the main event loop.
-
- If invalidate is true, the entire world is redrawn. Otherwise, only the changed
- portions of world are updated.
- */
-
- // If world manager is in use for world, this will update all worlds registered with manager
- void DoWorldUpdate(GEWorldPtr world, Boolean invalidate);
-
- // Updates ONLY the specified GEWorld
- void Update1GEWorld(GEWorldPtr world, Boolean invalidate);
-
- /*
- Call from event handler when mouse down in the window containing world.
- Returns true if mouseDown was handled by a sensor, false otherwise.
- */
-
- // If world manager is in use for world, this will check sensors
- // in all worlds registered with manager
- Boolean MouseDownInSensor(GEWorldPtr world, Point gMousePt);
-
- // Checks sensors in ONLY the specified GEWorld
- Boolean MouseDownIn1World(GEWorldPtr world, Point gMousePt);
-
- //Services provided by Display Controller for Graphic Elements
-
- //Creation and destruction
-
- /*
- Low-level element creation. This function allocates an element, calls its
- GraphicLoadFunc proc (if any), and links it into the world. In itself, it
- initializes only the fields element->objectID and element-<drawPlane (in
- addition to those initialized by the GraphicLoadFunc).
-
- It is normally called only from a higher-level creation function.
- */
-
- GrafElPtr NewGrafElement(GEWorldPtr world, OSType id, short plane, short elemSize,
- GraphicLoadFunc loadProc, short resStart, short nRsrcs);
-
- /*
- Unlinks a graphic element from its world and disposes of it. Calls element's
- cleanupProc, if any. Recursively disposes of element's slaveGrafEl(s). If element
- has a masterGrafEl, sets masterGrafEl->slaveGrafEl to nil.
- */
-
- void DisposeGrafElement(GEWorldPtr world, OSType objectID);
-
- //Access
-
- /*
- Returns individual element with ID objectID
- */
-
- GrafElPtr FindElementByID(GEWorldPtr world, OSType objectID);
-
- /*
- Returns first element with drawPlane == plane. For collision checking, etc.
- */
-
- GrafElPtr ElementsInPlane(GEWorldPtr world, short plane);
-
- //Control
-
- /*
- ShowElement shows or hides a Graphic Element, depending on the value of showIt
- */
-
- void ShowElement(GEWorldPtr world, OSType elementID, Boolean showIt);
-
- /*
- Test whether element is presently visible
- */
-
- Boolean ElementVisible(GEWorldPtr world, OSType elementID);
-
- /*
- Move graphic elements
- */
-
- void MoveElement(GEWorldPtr world, OSType elementID, short dh, short dv);
- void MoveElementTo(GEWorldPtr world, OSType elementID, short h, short v);
-
- // Alternate interface: avoid lookup when GrafElPtr already available, for example
- // in Autochange procedures.
- // For PtrMoveElementTo(), h and v are in absolute pixels if doScale is false
-
- void PtrMoveElement(GEWorldPtr world, GrafElPtr element, short dh, short dv);
- void PtrMoveElementTo(GEWorldPtr world, GrafElPtr element, short h, short v, Boolean doScale);
-
- /*
- Sets element's plane to newPlane
- */
-
- void SetElementPlane(GEWorldPtr world, OSType elementID, short newPlane);
-
- /*
- Set element's autochange parameters
- */
-
- void SetAutoChange(GEWorldPtr world, OSType elementID, AutoChangeProc changeProc,
- Ptr changeData, short changeIntrvl);
-
- /*
- Set element's collision parameters. No collision if collidePlane == 0
- */
-
- void SetCollision(GEWorldPtr world, OSType elementID, CollisionProc collideProc,
- short collidePlane);
-
- /*
- Set element's custom dispose proc.
- */
-
- void SetCleanupProc(GEWorldPtr world, OSType elementID, CleanupProc elemCleanup);
-
- //Miscellaneous sensor services
-
- //Add sensor to world's sensor list and make it active
- void AddSensorToList(GEWorldPtr world, OSType id, Rect *sensorRect);
-
- //Remove sensor from world's sensor list and make it inactive
- void RemoveSensorFromList(GEWorldPtr world, OSType id);
-
- //Set sensor's actionProc to newAction
- void SetSensorAction(GEWorldPtr world, OSType sensorID, SensorAction newAction);
-
- //Get element's entry in world->sensorList, if any
- SListEntryPtr FindSensorListEntry(GEWorldPtr world, OSType sensorID);
-
- /*
- If anything in a world is changed from OUTSIDE the Graphic Elements system,
- call this procedure with the affected rectangle.
- */
-
- void ChangedRect(GEWorldPtr world, Rect *chgdRect);
-
-
- /*
- GraphicLoadFunc which:
-
- 1) Searches to see if the required graphics are already available in this world,
- and copies their parameters if so,
- 2) Otherwise, creates a new offscreen GWorld of an appropriate size, and
- loads nResources PICTs from an open resource file into it, starting
- at the PICT with resource number startResNum
-
- This is the default loaderFunc of a newly created GEWorld.
- */
-
- pascal Boolean LoadPICTElement(GEWorldPtr world, GrafElPtr element,
- short startResNum, short nResources);
-
-
- /*
- GraphicLoadFunc which does nothing except initialize the appropriate fields.
- For Graphic Elements which have no permanent offscreen representations, e.g.
- strings or fills.
- */
-
- pascal Boolean NoLoader(GEWorldPtr world, GrafElPtr element,
- short startResNum, short nResources);
-
-
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #endif